#include"Name_pairs.h"

void Name_pairs::read_name()
{
  cout<<"please input a list of name with each name is seperatd by blank(ended with enter)"<<endl;
  string str;
  do
    {
      cin>>str;
      name.push_back(str);

    }
  while(getchar()!='\n');
}

void Name_pairs::read_age()
{
  cout<<"please input a list of age whose total number is equal to that in the previous list of name(ended with enter)"<<endl;
  double age1;
  do
    {
      cin>>age1;
      age.push_back(age1);
    }
  while(getchar()!='\n');
}

void Name_pairs::sort()
{
  int n=name.size();
  for(int i=1;i<=n-1;i++)
    for(int j=0;j<n-1;j++)
      {
	if(name[j]>name[j+1])
	  {
	    swap(name[j],name[j+1]);
	    swap(age[j],age[j+1]);
	  }
	else
	  ;
      }
}

ostream& operator<<(ostream& os,const Name_pairs& temp)
{
  for(int i=0;i<temp.name.size();i++)
    os<<'('<<temp.name[i]<<','<<temp.age[i]<<')'<<endl;
  return os;
}

bool Name_pairs::operator==(const Name_pairs& temp)
{
  bool flag=true;
  if(name.size()!=temp.name.size())
    flag=false;
  else
    {
      for(int i=0;i<temp.name.size();i++)
	if((name[i]!=temp.name[i])||(age[i]!=temp.age[i]))
	  flag=false;
    }
  return flag;
}

bool Name_pairs::operator!=(const Name_pairs& temp)
{
  return !(*this==temp);
}
